<?php

class PetSkill
{
	private static $IDs=array({IDs});

	public static function loadPetSkill($id)
	{
		if(!self::exists($id))
			throw new CException("unknown petSkill[$id]");

		$classname='PetSkill_'.$id;
		return call_user_func(array($classname, 'getInstance'));
	}

	public static function exists($id)
	{
		return array_key_exists($id, self::$IDs);
	}
    
    public function apply($self, &$enemy)
    {
        if($this->level==0)
            return false;
            
        $consumeMp = $this->consumeMp();
        if ($thos->mp < $consumeMp)
            return false;
        
        if(!$this->applySucc())
            return new FightPetActionResult($this->name);

        $effects = $this->effects($self,$enemy,$this->level);
        if($enemy->defending){
            foreach($effects as &$effect) {
                if($this->causeEnemyDamage($effect))
                    $effect->value=int($effect->value/4);
            }
        }        
        $effects[] = new FightPetActionEffect('self','mp','change',-$consumeMp);
        return new FightPetActionResult($this->name, $effects);
    }

    private function applySucc()
    {
        if($this->succRatio>=100)
            return true;
        $ratio=mt_rand(1, 100);
        return $ratio<=$this->succRatio ? true:false;
    }

    private function causeEnemyDamage(&$effect)
    {
        return $effect->target=='enemy'&& 
                $effect->attribute=='hp'&& 
                $effect->changeOrSet=='change'&& 
                $effect->value<0;
    }
    
    protected function effects(&$self,&$enemy,$skillLevel)
    {
        assert(false);
    }
    
    protected function consumeMp()
    {
        assert(false);
    }
}

?>
